package com.hushow.demo.process;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author hushow
 */
@Slf4j
public class MyPersonItemProcessor implements ItemProcessor<List<MyPerson>, List<MyPerson>> {

    @Override
    public List<MyPerson> process(final List<MyPerson> persons) throws Exception {

        List<MyPerson> personList = persons.stream().map(person->{
            final String firstName = person.getFirstName().toUpperCase();
            final String lastName = person.getLastName().toUpperCase();
            MyPerson person1 = new MyPerson().setFirstName(firstName+"-process").setLastName(lastName+"-process");
            return person1;
        }).collect(Collectors.toList());

        log.info("process personList:"+ JSONObject.toJSONString(personList));
        return personList;
    }
}
